import Vue from 'vue';
import App from './App.vue';
import router from './router';
import ElementUI from 'element-ui';
import echarts from 'echarts';
// import axios from '@/assets/js/axios';
import axios from '@/assets/js/require';
import store from './store';
import * as filters from '@/assets/js/filters';
import 'element-ui/lib/theme-chalk/index.css';
import '@/assets/css/iconfont.css';
import '@/assets/js/JsonExportToCSV.js';

Vue.config.productionTip = false;

Vue.prototype.$echarts = echarts;
// Vue.prototype.$post = post;
// Vue.prototype.$get = get;
Vue.use(ElementUI);
Vue.use(axios);


Object.keys(filters).forEach(key => {
    Vue.filter(key, filters[key]);
});

//页面权限处理
router.beforeEach((to, from, next) => {
    if (to.meta.authList) {
        store.dispatch('CHECK_AUTH', to.meta.authList).then(res => {
            to.meta.authResult = res;
            if (!to.meta.authList.auth_page || res.auth_page) {
                next();
            }else {
                console.log('无权限页面');
                return;
            }
        }).catch(error => {
            router.push({
                path: '/',
                query: {
                    TO: escape(JSON.stringify({name: to.name, path: to.path, query: to.query, params: to.params}))
                }
            });
        });
    } else {
        next();
    }
});

new Vue({
    router,
    store,
    render: h => h(App),
}).$mount('#app');

